# PLOTS RESPECTABILITY POLITICS EVERYDAY POLITICS
# ALAN YAN
# SEPTEMBER 25, 2020

#### SETUP ####
#clear environment
rm(list = ls())

#load libraries
library(pacman)
p_load(tidyverse,
       dotwhisker,
       broom,
       DeclareDesign,
       scales,
       gridExtra)

#load data
dt <- read_rds("01-data/clean-everyday-rps")

#### COEF PLOT ####
#### * BOTHERED 1 ####
dt %>%
  lm_robust(bothered1_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.bothered1

dwplot(model.bothered1) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("Scenario 1: How Bothered?") +
  theme(plot.title = element_text(hjust = .5)) +
  xlim(-.5, 1) -> coef_plot.bothered1
coef_plot.bothered1

#### * IMPORTANCE 1 ####
dt %>%
  lm_robust(important1_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.important1

dwplot(model.important1) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S1: Impt. to Change Behavior?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.important1
coef_plot.important1

#### * TELL 1 ####
dt %>%
  lm_robust(tell1_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.tell1

dwplot(model.tell1) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S1: Approp. to Say Something?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.tell1
coef_plot.tell1

#### * BOTHERED 2 ####
dt %>%
  lm_robust(bothered2_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.bothered2

dwplot(model.bothered2) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("Scenario 2: How Bothered?") +
  theme(plot.title = element_text(hjust = .5)) +
  xlim(-.5, 1) -> coef_plot.bothered2
coef_plot.bothered2

#### * IMPORTANCE 2 ####
dt %>%
  lm_robust(important2_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.important2

dwplot(model.important2) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S2: Impt. to Change Behavior?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.important2
coef_plot.important2

#### * TELL 2 ####
dt %>%
  lm_robust(tell2_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.tell2

dwplot(model.tell2) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S2: Approp. to Say Something?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.tell2
coef_plot.tell2

#### * BOTHERED 3 ####
dt %>%
  lm_robust(bothered3_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.bothered3

dwplot(model.bothered3) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("Scenario 3: How Bothered?") +
  theme(plot.title = element_text(hjust = .5)) +
  xlim(-.5, 1) -> coef_plot.bothered3
coef_plot.bothered3

#### * IMPORTANCE 3 ####
dt %>%
  lm_robust(important3_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.important3

dwplot(model.important3) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S3: Impt. to Change Behavior?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.important3
coef_plot.important3

#### * TELL 3 ####
dt %>%
  lm_robust(tell3_n ~ rps_index + linked_fate_n + idimpt_n +
              r_age_n + r_edu_n + r_income_n + r_sex,
            data = .) %>%
  tidy() -> model.tell3

dwplot(model.tell3) %>%
  relabel_predictors(
    "rps_index" = "RPS",
    "linked_fate_n" = "Linked Fate",
    "idimpt_n" = "Racial Identity Importance",
    "r_age_n" = "Age",
    "r_edu_n" = "Education",
    "r_income_n" = "Income",
    "r_sexFemale" = "Female"
  ) +
  geom_vline(xintercept = 0, linetype = "dashed") +
  ggtitle("S3: Approp. to Say Something?") +
  theme(plot.title = element_text(hjust = .5),
        axis.text.y = element_blank()) +
  xlim(-.5, 1) -> coef_plot.tell3
coef_plot.tell3

#### BRING PLOTS TOGETHER ####
grid.arrange(coef_plot.bothered1,
            coef_plot.important1,
            coef_plot.tell1,
            coef_plot.bothered2,
            coef_plot.important2,
            coef_plot.tell2,
            coef_plot.bothered3,
            coef_plot.important3,
            coef_plot.tell3,
            ncol = 3,
            nrow = 3,
            widths = c(3, 2, 2),
            heights = c(2, 2, 2)) -> coef_plot.scenarios
ggsave("03-plots/fig-4.pdf", coef_plot.scenarios, width = 10, height = 12)

